n, m = map(int, input().split())
items = [tuple(map(int, input().split())) for _ in range(m)]
dp = [0] * (n + 1)
for item_v, item_p in items:
    for j in range(n, item_v - 1, -1):
        dp[j] = max(dp[j], dp[j - item_v] + item_v * item_p)
print(dp[-1])
